extends StateBase


func enter():
	selectEnemy()
	moveEnemy()
	enemyExecuteCommand()
	

func exit():
	pass


func run(delta):
	pass


func selectEnemy():
	ownerNode.currentSelectEnemyInst = ownerNode.findEnemyInstByData(BattleData.findEnemyActionNotFinish()) 
	

func moveEnemy():
	var targetHeroData = BattleData.getRandomHero()
	
	var enemyCellPos = ownerNode.currentSelectEnemyInst.data.battlePos
	var enemyMove = ownerNode.currentSelectEnemyInst.data.getPropMove()
	var enemyMovableCellPosArr = ownerNode.bfsFindMoveableCells(enemyCellPos, enemyMove, BattleData.herosCellPosArr())
	
	var moveTargetPos = Vector2.INF
	var minDistance = 100000000
	var minDistanceCellPos = Vector2.INF
	for cellPos in enemyMovableCellPosArr:
		var distance = ownerNode.calcCellDistance(cellPos, targetHeroData.battlePos)
		if distance < minDistance:
			minDistance = distance
			minDistanceCellPos = cellPos
			
	ownerNode.currentSelectEnemyInst.processMove(minDistanceCellPos, onArriveTarget)
	

func onArriveTarget():
	print("onArriveTarget")


func enemyExecuteCommand():
	pass
